package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/manage")
@RestController
public class ManagerController {


    @Autowired
    private ManagerService managerService;

    /**
     * 分页查询用户列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = managerService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 查看单个用户信息
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity findById(@PathVariable("userId") Long userId) {
        return ResponseEntity.ok(managerService.findById(userId));
    }

    /**
     * 查询指定用户发布的所有视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid ) {
        PageResult result = managerService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(result);
    }

    /**
     *查询动态
     * @param page
     * @param pagesize
     * @param uid
     * @param state
     * @return
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,Integer state ) {
        PageResult result = managerService.findAllMovements(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }

    /**
     * 查看动态详情
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity movement(@PathVariable("id") String id){
        MovementsVo vo = managerService.movementDetail(id);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查看评论
     */
    @GetMapping("/messages/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String messageID){

        PageResult pr = managerService.comments(messageID,page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 用户冻结
     */
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map map){
        Map reMap = managerService.freeze(map);
        return ResponseEntity.ok(reMap);
    }
    /**
     * 用户解冻
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody Map map){
        Map reMap = managerService.unfreeze(map);
        return ResponseEntity.ok(reMap);
    }
}
